package cn.yl.caner.service;

import java.sql.SQLException;

import cn.yl.caner.dao.ChangeDao;
import cn.yl.caner.domain.ChangeData;
import cn.yl.caner.utils.MyDataSourceUtils;

public class ChangeService {

	//service层，对修改信息提交事务，转换至DAO层
		public int change( ChangeData changedata) {
			int i = 0;
			ChangeDao changedao = new ChangeDao();
	 		try {
	 			//获取连接，并设置事务
				MyDataSourceUtils.start();
				i = changedao.changeAccount(changedata);
			} catch (SQLException e) {
				try {
					//失败回滚
					MyDataSourceUtils.rollback();
				} catch (SQLException e1) {
					System.out.println("事物无法回滚");
				}
				e.printStackTrace();
				System.out.println("事物提交失败！");
			} finally {
					try {
						//提交事务
						MyDataSourceUtils.commit();
					} catch (SQLException e) {
						e.printStackTrace();
						System.out.println("事物无法进行提交");
				}
			}
	 		return i;
		}
}
